package pl.edu.agh.io.gpstracker.server.service.handler;

import net.customware.gwt.dispatch.server.ActionHandlerRegistry;
import net.customware.gwt.dispatch.server.ExecutionContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pl.edu.agh.io.gpstracker.client.action.SendMessageAction;
import pl.edu.agh.io.gpstracker.client.result.VoidResult;
import pl.edu.agh.io.gpstracker.service.MessageService;

import com.adeoservices.gwt.dispatch.spring.server.handler.SpringActionHandler;

/**
 * 
 * @author wkedzior
 * 
 */
@Component
public class SendMessageHandler extends
		SpringActionHandler<SendMessageAction, VoidResult> {

	@Autowired
	private MessageService messageService;

	@Autowired
	public SendMessageHandler(ActionHandlerRegistry actionHandlerRegistry) {
		super(actionHandlerRegistry);

	}

	@Override
	public Class<SendMessageAction> getActionType() {
		return SendMessageAction.class;
	}

	@Override
	public VoidResult execute(SendMessageAction action, ExecutionContext context) {
		messageService.sendMessage(action.getMessagesDto());
		return null;
	}

	@Override
	public void rollback(SendMessageAction action, VoidResult result,
			ExecutionContext context) {
	}
}
